package cn.webrx.bs.servlet;

import cn.webrx.bs.service.AdminLogDao;
import cn.webrx.bs.service.AdminLogImpl;
import cn.webrx.bs.utils.IPUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;

/**
 * <p>功能描述: </p>
 *
 * @author webrx
 * @version 1.0
 * @date 2020-08-06 11:48
 */
@WebServlet("/admin/logout")
public class AdminLogout extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        AdminLogDao log = new AdminLogImpl();
        log.add("安全退出",new Date(), IPUtil.ipToLong(req.getRemoteAddr().equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : req.getRemoteAddr()),session.getAttribute("admin").toString());
        session.removeAttribute("admin");
        session.removeAttribute("truename");
        resp.sendRedirect("/");  // /index
    }
}
